import * as THREE from "../../lib/three.module";

const publicLoadCallback = function (object, fileSize, objectTree) {
  this.modelObject = object;
  const { animations, userData } = object;
  const { layers } = userData || {};
  if (animations && animations.length > 0) {
    this.mixer = new THREE.AnimationMixer(object);
    const action = this.mixer.clipAction(object.animations[0]);
    action.play();
  }

  object.traverse((child) => {
    if (child.isMesh) {
      child.castShadow = true;
      child.receiveShadow = true;
    }
  });

  this.scene.add(object);
  this.setScaleToFitSize(object);
  this.setAxisDirection(objectTree); // 先调整坐标轴
  this.setPositionToFitGrid(object); // 再让模型紧贴地面
  this.collectModalInfo(objectTree, fileSize);
  this.panel === '1' && this.createPanel(layers);
};

export default publicLoadCallback;